package com.naotebuk.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DaoFactory {

	// private static String driver = "com.mysql.jdbc.Driver";
//	private static String url = "jdbc:postgresql://ec2-54-232-241-2.sa-east-1.compute.amazonaws.com";
//	private static String usuario = "postgres";
//	private static String senha = "tanimoto";
	
	// private static String driver = "com.mysql.jdbc.Driver";
		private static String url = "jdbc:mysql://localhost:3306/naotebuk";
		private static String usuario = "root";
		private static String senha = "";

	public Connection getConnection2() {
		try {
			return DriverManager.getConnection(url, usuario, senha);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	// private methods
	public static Connection getConnection() {
		DataSource ds = null;
		Connection con = null;
		InitialContext context = null;
		try {
			context = new InitialContext();
			ds = (DataSource) context.lookup("java:comp/env/jdbc/naotebuk");
			con = ds.getConnection();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
}
